/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package lesson10;

import java.util.Random;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author netcracker
 */
public class OneWriteThread implements Runnable {

    IVector vector;
    Random r = new Random();
    public OneWriteThread(IVector vector) {
        this.vector = vector;
    }

    @Override
    public synchronized void run() {

        for (int i = 0; i < vector.getLength(); i++) {
            while (vector.isEdited()) {
                Thread.yield();
            }
            vector.set(r.nextDouble(), i);
            System.out.println("Write: "+vector.get(i)+" on position "+i);
            vector.setEdited(true);
            notifyAll();
        }
    }
}
